package com.yzz.hzraisedust.hzraseidust.main.alarm;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yzz.hzraisedust.hzraseidust.R;
import com.yzz.hzraisedust.hzraseidust.modelbean.AlarmItemBean;
import com.yzz.hzraisedust.hzraseidust.modelbean.MapItemBean;

import java.util.List;

/**
 * Created by zhengzhen on 2017/8/20.
 */

public class AlarmAdapter  extends BaseAdapter{
    private List<AlarmItemBean> alarmInfoBeanList;

    private Context mContext;
    public AlarmAdapter(Context context,List<AlarmItemBean> beans){
        alarmInfoBeanList = beans;
        mContext = context;
    }

    @Override
    public int getCount() {
        return alarmInfoBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return alarmInfoBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
       AlarmViewHold viewHold = null;
       if(view == null){
           view = LayoutInflater.from(mContext).inflate(R.layout.alarm_list_item_layout,null,false);
           viewHold = new AlarmViewHold();
           viewHold.areaNameTextView = view.findViewById(R.id.list_item_area_name);
           viewHold.countNameTextView = view.findViewById(R.id.list_item_count_name);
           viewHold.onelineNameTextView = view.findViewById(R.id.list_item_online_name);
           viewHold.offlineNameTextView = view.findViewById(R.id.list_item_offline_name);
           viewHold.alarmCountNameTextView = view.findViewById(R.id.list_item_alarm_count_name);
           view.setTag(viewHold);
       }
       if(viewHold == null){
           viewHold = (AlarmViewHold)view.getTag();
       }
        AlarmItemBean item = alarmInfoBeanList.get(i);
       viewHold.areaNameTextView.setText(""+item.getCityName());
       viewHold.countNameTextView.setText(""+item.getAllNum());
       viewHold.offlineNameTextView.setText(""+item.getOfflineNum());
       viewHold.onelineNameTextView.setText(""+item.getOnlineNum());
       viewHold.alarmCountNameTextView.setText(""+item.getAlarmNum());

        return view;
    }

    class AlarmViewHold{
        private TextView areaNameTextView;
        private TextView countNameTextView;
        private TextView onelineNameTextView;
        private TextView offlineNameTextView;
        private TextView alarmCountNameTextView;
    }
}
